#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
int a[MAX],c[MAX],x[MAX*4];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    int n,m;
    cin>>n>>m;
    for(int i = 1;i <= n;i++)cin>>a[i];
    for(int i = 1;i <= m;i++)cin>>c[i];
    int T;
    cin>>T;
    for(int i = 1;i <= T;i++)
    {
        cin>>x[i*4]>>x[i*4+1]>>x[i*4+2]>>x[i*4+3];
        cout<<n<<endl;
    }
    return 0;
}
